package com.group.controller;

import com.group.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.entity.Comment;
import utils.BaseController;

import javax.servlet.http.HttpServletResponse;

@Api(tags = "评论信息")
@Controller
@RequestMapping(value = "/comment", produces = "text/html;charset=utf-8")
public class CommentController extends BaseController {
    @Autowired
    private CommentService commentService;

    @ApiOperation("增加评论")
    @RequestMapping(value = "addComment.do")
    @ResponseBody
    public String addComment(Comment comment, HttpServletResponse resp) {
        System.out.println("增加评论:"+comment);
        int result = commentService.addComment(comment);
        if (result!=1){
            String errorMsg="插入评论失败";
           return writerErrorResult(errorMsg,resp);
        }
        return writerSuccessResult(result,resp);
    }

    @ApiOperation("展示商品评论")
    @RequestMapping(value = "showComment.do")
    @ResponseBody
    public String showCommentByGoodId(Long goodId, HttpServletResponse resp){
        System.out.println("展示商品评论:"+goodId);
        return writerSuccessResult(commentService.showCommentByGoodId(goodId),resp);
    }

    @ApiOperation("通过评论ID删除评论")
    @RequestMapping(value = "deleteCommentById.do")
    @ResponseBody
    public String deleteComment(Long id, HttpServletResponse resp){
        System.out.println("通过评论ID删除评论:"+id);
        return writerSuccessResult(commentService.deleteCommentById(id),resp)  ;
    }

}
